package br.com.medmark.model.hibernate.dao;

import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

import br.com.medmark.model.hibernate.Horario;
import br.com.medmark.model.hibernate.Paciente;

public class PacienteDAO extends GenericoDAOImpl<Paciente>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -3854381957026769495L;
	
	private static PacienteDAO pacienteDAO = null;
	
	private PacienteDAO(){
		
		
	}
	
	public static PacienteDAO getInstance(){
		if (pacienteDAO == null) {
			pacienteDAO = new PacienteDAO();
		}
		
		return pacienteDAO;
		
	}
	
	public Paciente getPaciente(Long codigo) {
		String sql = "FROM Paciente p Where p.codigo = :codigo";
		
		TypedQuery<Paciente> query = this.entityManager.createQuery(sql, Paciente.class);
		query.setParameter("codigo", codigo);
	
		try {
			return query.getSingleResult();
		} catch (NoResultException ex) {
			return null;
		}
	}
}
